package com.wzw.springboot.principle.use.websock.second;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @author Wangzhiwen
 */
@Configuration
@EnableWebSocket
@RequiredArgsConstructor
public class PrincipleWebSocketConfig implements WebSocketConfigurer {

    private final PrincipleWebSocketHandler webSocketHandler;

    private final PrincipleHandshakeInterceptor handshakeInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(webSocketHandler, "/socket2")
                .addInterceptors(handshakeInterceptor)
                .setAllowedOrigins("*");
    }
}
